﻿using System;
using System.Collections.Generic;
using Educational.Model.Entity;
using NHibernate;
using NHibernate.Criterion;


namespace Educational.Model.EntityManager
{
    public class SchoolRoleCategoryManager
    {
        public static void Add(ISession session, SchoolRoleCategory an)
        {
            session.Save(an);
        }

        public static void Delete(ISession session, SchoolRoleCategory an)
        {
            session.Delete(an);
        }

        public static void Update(ISession session, SchoolRoleCategory an)
        {
            session.Update(an);
        }

        public static SchoolRoleCategory Get(ISession session, int itemId)
        {
            return session.Get<SchoolRoleCategory>(itemId);
        }

        public static SchoolRoleCategory Get1(ISession session, string categoryName)
        {
            ICriteria c = session.CreateCriteria(typeof(SchoolRoleCategory));
            c.Add(Expression.Eq("categoryName", categoryName));
            return c.UniqueResult<SchoolRoleCategory>();
        }

        public static IList<SchoolRoleCategory> Gets1(ISession session)
        {
            ICriteria c = session.CreateCriteria(typeof(SchoolRoleCategory));
            c.SetFetchMode("schoolRoles", FetchMode.Eager);
            c.SetResultTransformer(NHibernate.CriteriaUtil.DistinctRootEntity);
            return c.List<SchoolRoleCategory>();
        }
    }
}
